﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>@ViewBag.Title</title>
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
    <script type="text/javascript">

        var Type;
        var Url;
        var Data;
        var ContentType;
        var DataType;
        var ProcessData;
        var method;

        function CallService() {
            $.ajax({
                type: Type,
                url: Url,
                data: Data,
                contentType: ContentType,
                dataType: DataType,
                processdata: ProcessData,
                success: function (msg) {
                    ServiceSucceeded(msg);
                },
                error: ServiceFailed
            });
        }

        function ServiceFailed(result) {
            alert('test');
            alert('Service call failed: ' + result.status + '' + result.statusText);
            Type = null;
            Url = null;
            Data = null;
            ContentType = null;
            DataType = null;
            ProcessData = null;
        }

        function GetArticulos() {
            var uesrid = "1";
            Type = "GET";
            Url = "http://localhost:1547/ArticuloService.svc/Articulos";
            DataType = "jsonp";
            ProcessData = false;
            method = "Articulos";
            CallService();
        }

        function ServiceSucceeded(result) {
            if (DataType == "jsonp") {

                $("#tbl > tbody").append('<tr><th>Nombre</th><th>Precio</th><th>Cantidad</th></tr>');

                for (var i = 0; i < result.length; i++) {
                    $("#tbl > tbody").append('<tr><td>' + result[i].Nombre + '</td><td>' + result[i].Precio + '</td><td>' + result[i].Cantidad + '</td></tr>');
                }

            }
        }

        function ServiceFailed(xhr) {
            alert(xhr.responseText);
            if (xhr.responseText) {
                var err = xhr.responseText;
                if (err)
                    error(err);
                else
                    error({ Message: "Unknown server error." })
            }
            return;
        }

        $(document).ready(
         function () {
             try {
                 GetArticulos();
             } catch (exception) {
              }
         }
);

   
    </script>
</head>
<body>
    <div id="header">
        <h1>
        </h1>
        @if (Session["auth"] == null)
        {
            using (Html.BeginForm("Ingreso", "Home", FormMethod.Post))
            {
            @Html.TextBox("user")
       
            <input type="submit" value="Ingresar" />
            }
        }
        else
        {
            using (Html.BeginForm("Salir", "Home", FormMethod.Post))
            {
            @Html.Label(Session["nombre"].ToString())
            <input type="submit" value="Salir" />
            }


        }
        <ul id="navlist">
            <li class="first"><a href="/" id="current">Home</a></li>
            <li><a href="/Store/">Store</a></li>
            @if (Session["auth"] != null)
            {
                <li><a href="/Articulo/">Mis articulos</a></li>
                <li><a href="/Panel/">Panel de Actividades</a></li>
            }
        </ul>
    </div>
    @RenderBody()
</body>
</html>
